import fetch from './fetch';
import vue from 'vue'
import { useMessage } from '@/hooks/web/useMessage';
  // 信息提示框
const { notification } = useMessage();
export function post(cThis,rxUrl,data) {
  return new Promise((resolve, reject) => {
    fetch({
      url: rxUrl,
      method: 'post',
      data
    }).then(response => {
      const data = response.data;
      if('000000' == data.resultCode){
        resolve(data);
      }else{
        console.log('['+data.resultCode+'] '+data.resultMessage)
        notification.error(
          {
            message: '操作失败',
            description: '['+data.resultCode+'] '+data.resultMessage,
            duration: 3,
          }
        );
        reject(data);
      }                    
    }).catch(error => {
      console.log('[网络错误]：' + error.message)
      notification.error(
        {
          message: '网络错误',
          description: error.message,
          duration: 3,
        }
      );
    	// cThis.$Message.error({
      //       content:'[网络错误]：' + error.message,
      //       duration:3
      //   });
        reject(error);
    });
  });
}

export function get(rxUrl,data) {
  return new Promise((resolve, reject) => {
    fetch({
      url: rxUrl,
      method: 'get',
      data
    }).then(response => {
      const data = response.data;
      if('000000' == data.resultCode){
        resolve(data);
      }else{
        console.log('['+data.resultCode+'] '+data.resultMessage)
        notification.error(
          {
            message: '操作失败',
            description: '['+data.resultCode+'] '+data.resultMessage,
            duration: 3,
          }
        );
//      	cThis.$Message.error({
        //     content:'['+data.resultCode+'] '+data.resultMessage,
        //     duration:3
        // });
        reject(data);
      }                    
    }).catch(error => {
      console.log('[网络错误]：' + error.message)
      notification.error(
        {
          message: '网络错误',
          description: error.message,
          duration: 3,
        }
      );
    	// cThis.$Message.error({
      //       content:'[网络错误]：' + error.message,
      //       duration:3
      //   });
        reject(error);
    });
  });
}